package com.insleton.admin.employee.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

import java.util.Date;

@NamedQueries({
        @NamedQuery(name = "Department.selectAll", query = "select d from Department d"),
        @NamedQuery(name = "Department.selectAll.named.param", query = "select d from Department d where d.name = :name"),
        @NamedQuery(name = "Department.selectAll.param", query = "select d from Department d where d.name = ?1"),
        // HQL语句单独写的时候，别名使用空格是OK的，这里可能是语法校验需要使用as
        @NamedQuery(name = "Department.queryLink", query = "select e.id, e.name, e.deptId, d.name as deptName, d.code from Employee e, Department d where e.deptId = d.id"),
        @NamedQuery(name = "Department.queryLink.param", query = "select e.id, e.name, e.deptId, d.name as deptName, d.code from Employee e, Department d where e.deptId = d.id and d.name = ?1"),
        @NamedQuery(name = "Department.queryLink.named.param", query = "select e.id, e.name, e.deptId, d.name as deptName, d.code from Employee e, Department d where e.deptId = d.id and d.name = :name"),
        // 如果直接使用构造函数，那么别名可能是不要的。只看类型即可。对象不需要包名
        @NamedQuery(name = "Department.queryLinkConstructor", query = "select new Department(e.id, e.name, e.deptId, d.name, d.code) from Employee e, Department d where e.deptId = d.id")
})
@Entity
public class Department {
    @Id
    @Column
    private String id;
    @Column
    private String name;
    @Column
    private Integer states;
    @Column
    private String code;
    @Column
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;
    private transient String deptId;
    private transient String deptName;

    public Department() {
    }

    public Department(String id, String name, String deptId, String deptName, String code) {
        this.id = id;
        this.name = name;
        this.code = code;
        this.deptId = deptId;
        this.deptName = deptName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getStates() {
        return states;
    }

    public void setStates(Integer states) {
        this.states = states;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }
}
